package com.lt.integration.jpa.component.hibernate;

import javax.persistence.metamodel.Attribute;
import java.util.HashMap;
import java.util.Map;

/**
 * 更新对象类
 * @author xiaobin
 */
public class Updater {

	@Deprecated
	public static Updater instance() {
		return new Updater();
	}

	public static Updater INSTANCE = new Updater();

	/**
	 * 必须更新的字段
	 * 
	 * @param property
	 * @return
	 */
	@Deprecated
	public Updater include(Attribute<?, ?> property, Object value) {
		return set(property, value);
	}

	public Updater set(Attribute<?, ?> property, Object value) {
		includeProperties.put(property, value);
		return this;
	}

	public UpdateWhere where() {
		return new UpdateWhere(condition);
	}

	/**
	 * 条件
	 * @param property
	 * @param value
	 * @return
	 */
	public Updater id(Attribute<?, ?> property, Long value) {
		condition.put(property, value);
		return this;
	}

	public Updater equal(Attribute<?, ?> property, Object value) {
		condition.put(property, value);
		return this;
	}
	
	private Map<Attribute<?, ?>, Object> includeProperties = new HashMap<>();

	public Map<Attribute<?, ?>, Object> getIncludeProperties() {
		return includeProperties;
	}
	
	private Map<Attribute<?, ?>, Object> condition = new HashMap<>();

	public Map<Attribute<?, ?>, Object> getCondition() {
		return condition;
	}
	
//	public static enum UpdateCondition {
//		EQUAL, IS_NULL, IS_NOT_NULL, NOT_EQUAL, GT, GE, LT, LE, LIKE,
//	}
}
